package modelLayer;

import java.util.ArrayList;

public class DvdContainer {
    private ArrayList<Dvd> dvds;
    private static DvdContainer instance;
    
    private DvdContainer() {
        dvds = new ArrayList<Dvd>();
    }
    
    public static DvdContainer getInstance() {
        if (instance == null) {
            instance = new DvdContainer();
        }
        
        return instance;
    }
    
    public void addDvd(Dvd dvd) {
        dvds.add(dvd);
    }
    
    public Dvd findDvd(int barcode) {
        boolean found = false;
        int index = 0;
        while(index < dvds.size() && !found) {
            Dvd d = dvds.get(index);
            if(d.getBarcode() == barcode) {
                found = true;
            }
            else {
                index++;
            }
        }
        
        if(found) {
            return dvds.get(index);
        }
        else {
            return null;
        }
    }
    
    public void removeDvd(Dvd d) {
        dvds.remove(d);
    }
}
